package com.study.thread;

import java.util.List;
import java.util.UUID;
import java.util.concurrent.CopyOnWriteArrayList;

/**
 * @Description: 线程下安全的集合
 * @Param:
 * @return:
 * @Author: 朝花不迟暮
 * @Date: 2020/5/31
 */
public class CollectionTest
{
    public static void main(String[] args)
    {
//        Vector<Object> list = new Vector<>();
//        List<Object> list = Collections.synchronizedList(new ArrayList<>());
        List<String> list = new CopyOnWriteArrayList<>();
        for (int i = 1; i <= 10; i++)
        {
            new Thread(() -> {
                list.add(UUID.randomUUID().toString().substring(0,5));
                System.out.println(list);
            }, String.valueOf(i)).start();
        }
    }
}
